package com.ck.server;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * @author ck
 * @date 2023/3/22 10:04
 */
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@MapperScan({"com.ck.autoconfig.tenant.mapper","com.ck.system.mapper","com.ck.task.quartz.mapper"})
@EnableScheduling
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableAdminServer
@Slf4j
@ComponentScan(basePackages = {
		"com.ck.common",
		"com.ck.framework",
		"com.ck.system",
		"com.ck.task",
		"com.ck.autoconfig",
		"com.ck.server",
		"org.jeecg.modules.jmreport","com.ck"
})
public class DemoApplication {

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext applicationContext = SpringApplication.run(DemoApplication.class, args);
		ConfigurableEnvironment env = applicationContext.getEnvironment();
		String protocol = "http";
		String swagger="swagger-ui.html";
		String path = env.getProperty("server.servlet.context-path");
		if (StringUtils.isEmpty(path)) {
			path = "";
		}
		log.info("\n----------------------------------------------------------\n\t" +
				"Application '{}' is running! Access URLs:\n\t" +
				"Local: \t\t{}://localhost:{}\n\t" +
				"External: \t{}://{}:{}\n\t" +
				"Swagger: \t{}://localhost:{}/{}\n\t"+
				"Profile(s): \t{}\n----------------------------------------------------------",
				env.getProperty("spring.application.name"),
				protocol,
				env.getProperty("server.port"),
				protocol,
				InetAddress.getLocalHost().getHostAddress(),
				env.getProperty("server.port"),
				protocol,
				env.getProperty("server.port"),
				swagger,
				env.getActiveProfiles());
	}
}
